//
//  NavigationController.swift
//  microblog
//
//  Created by cy on 2017/8/26.
//  Copyright © 2017年 Aisino. All rights reserved.
//

import UIKit

class NavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 隐藏导航条，自定义
        navigationBar.isHidden = true
    }
    

    /// 重写push方法，隐藏底部导航栏
    ///
    /// - Parameters:
    ///   - viewController: 跳转到的控制器
    ///   - animated: 是否动画
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? BaseController {
                var title = "返回"
                // 判断控制器的级数
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popVC), isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    func popVC() {
        popViewController(animated: true)
    }
}
